/**
 * FileName: PurchaseServiceImpl
 * Author:   Molzx
 * Date:     2019/10/4 21:20
 * Description: 采购申请
 */
package com.dgut.Service.impl;

import com.dgut.Service.IPurchaseService;
import com.dgut.dao.IPurchaseDao;
import com.dgut.dao.IPurchaseRcdDao;
import com.dgut.domain.Purchase;
import com.dgut.domain.PurchaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 〈采购申请〉
 */
@Service
public class PurchaseServiceImpl implements IPurchaseService {

    @Autowired
    private IPurchaseDao iPurchaseDao;

    @Autowired
    private IPurchaseRcdDao iPurchaseRcdDao;

    @Override
    public List<Purchase> findAll(PurchaseQuery purchaseQuery) {
        return iPurchaseDao.findAll(purchaseQuery);
    }

    @Override
    public List<Purchase> findAllLimit(PurchaseQuery purchaseQuery) {
//        Integer page=purchaseQuery.getPage();
//        Integer rows=purchaseQuery.getRows();
//        purchase.setStart((page - 1) * rows);
//        purchase.setRows(rows);
        List<Purchase> purchaseList = iPurchaseDao.findAllLimit(purchaseQuery);
        return purchaseList;
    }

    @Override
    public Integer findAllCountLimit(PurchaseQuery purchaseQuery) {
        return iPurchaseDao.findAllCountLimit(purchaseQuery);
    }

    @Override
    public Purchase findById(String id) {
        return iPurchaseDao.findById(id);
    }

    @Override
    @Transactional
    public Integer updatePurchase(Purchase purchase) {

        return iPurchaseDao.updatePurchase(purchase);
    }


    @Override
    @Transactional
    public Integer savePurchase(Purchase purchase) {
        return iPurchaseDao.savePurchase(purchase);
    }

    @Override
    @Transactional
    public Integer deletePurchase(String id) {
        //删除采购申请单的审批记录
        int c1 = iPurchaseRcdDao.deletePurchaseRecord(id);
        //删除采购申请单
        int c2 = iPurchaseDao.deletePurchase(id);
        System.out.println(c1 + c2);
        return c1 + c2 > 1 ? 2 : 0;
    }
}
